/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package nationsim.simulation;

import nationsim.api.Constants;
import nationsim.components.nation.Nation;
import nationsim.components.nation.NationState;
import nationsim.components.nation.NationStateValues;

/**
 *  The Class responsible for simulating all the variables and environemnts.
 * @author CJ
 */
public class NationSimulator {

    public static void simluateAINations(Nation[] nationList) {

    }

    public static void simulateNationOutCome(Nation nation){
        NationState state = nation.getState();
        genNationRevenue(state);
        genPopulationChange(state);
    }

    protected static void genPopulationChange(NationState state){
        int numCitiBill = Integer.parseInt((String)state.getInstanceValue(NationStateValues.NUM_CITIZENS_BILLIONS));
        double numCiti = numCitiBill * 1000000000;
        int deathRate = (int)((Math.random() * (Constants.MAX_DEATH_RATE + 1 - Constants.MIN_DEATH_RATE)) + Constants.MIN_DEATH_RATE);
        int numDeaths = (int)numCiti/10000 * deathRate;
        int birthRate = (int)((Math.random() * (Constants.MAX_BIRTH_RATE + 1 - Constants.MIN_BIRTH_RATE)) + Constants.MIN_BIRTH_RATE);
        int numBirth = (int)numCiti/2000 * birthRate;
        numCiti += numBirth - numDeaths;

        String output = ((Double)(numCiti/1000000000)).toString();
        System.out.println(output);
//        state.setInstanceValue(NationStateValues.NUM_CITIZENS_BILLIONS, output );
    }

    protected static void genNationRevenue(NationState state){
        //Generate Nation By Taxes Revenue
        int numCitiBill = Integer.parseInt((String)state.getInstanceValue(NationStateValues.NUM_CITIZENS_BILLIONS));
        double fedIncomeTax = Double.parseDouble((String)state.getInstanceValue(NationStateValues.FEDERAL_INCOME_TAX));
        int averageIncome = Integer.parseInt((String)state.getInstanceValue(Constants.UI_TEXT_INPUT_OPTIONS[Constants.NATIONAL_AVERAGE_INCOME]));

        state.setInstanceValue(NationStateValues.TAX_REVENUE, ((Double)(numCitiBill * 1000000000 * fedIncomeTax * averageIncome)).toString());

        //Add to treasury
        double total = Double.parseDouble((String)state.getInstanceValue(NationStateValues.FEDERAL_TREASURY));
        System.out.println(total);
        total += Double.parseDouble((String)state.getInstanceValue(NationStateValues.TAX_REVENUE));

        state.setInstanceValue(NationStateValues.FEDERAL_TREASURY, ((Double)total).toString());
    }
}
